package com.sinosoft.cloud.access.handler;

import com.sinosoft.cloud.access.crypto.CryptoBean;
import com.sinosoft.cloud.access.net.MessageObject;
import io.netty.channel.ChannelHandlerContext;

/**
 * Created by Administrator on 2018-1-4.
 */
public class EncryptHandler extends AbstractHandler {
    @Override
    MessageObject dealMessage(ChannelHandlerContext ctx, MessageObject messageObject) {

        String originalMsg = messageObject.getOriginalMsg().substring(73);
        if (!originalMsg.startsWith("<")){
            CryptoBean cryptoBean = getCryptoBean();
            if (null != cryptoBean){
                String encryt = cryptoBean.encryt(messageObject.getSendToBankMsg());
                messageObject.setSendToBankMsg(encryt);
            }
        }
        logger.info("返回银行加密后的报文：" + messageObject.getSendToBankMsg());
        return messageObject;
    }
}
